package com.sikao.app.ui;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sikao.app.R;
import com.sikao.app.adapter.MyFragmentPagerAdapter;
import com.sikao.app.fragment.BuyerOrderFragment;
import com.sikao.app.fragment.SellerOrderFragment;
import com.sikao.app.ui.base.BaseActivity;

import java.util.ArrayList;

/**
 * 卖家中心订单模块
 */
public class SellerOrderActivity extends BaseActivity implements View.OnClickListener{

	private TextView titleTv;
	private ImageView backIv;
	private ViewPager mPager;
	private ArrayList<Fragment> fragmentList;
	private TabLayout tabLayout;
	private String[] tabTitles = {"全部", "进行中", "仲裁中", "待评价", "已完成"};

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.activity_seller_order);
		super.onCreate(savedInstanceState);
	}

	@Override
	protected void initData() {

	}

	@Override
	protected void initView() {
		titleTv = (TextView) findViewById(R.id.title_middle_tv);
		backIv = (ImageView) findViewById(R.id.title_left_img);
		mPager = (ViewPager) findViewById(R.id.view_pager);
		tabLayout = (TabLayout) findViewById(R.id.sliding_tabs);
	}

	@Override
	protected void initListener() {
		backIv.setOnClickListener(this);
	}

	@Override
	protected void init() {
		titleTv.setText("卖家订单");
		backIv.setVisibility(View.VISIBLE);
		initFragment();
		tabLayout.setupWithViewPager(mPager);
		tabLayout.setTabMode(TabLayout.MODE_FIXED);
	}

	private void initFragment() {
		fragmentList = new ArrayList<Fragment>();
		//卖盘
		Fragment oneFragment = new SellerOrderFragment();
		Fragment twoFragment = new SellerOrderFragment();
		Fragment threeFragment = new SellerOrderFragment();
		Fragment fourFragment = new SellerOrderFragment();
		Fragment fiveFragment = new SellerOrderFragment();
		Bundle bundle1 = new Bundle();
		bundle1.putInt("type",0);
		Bundle bundle2 = new Bundle();
		bundle2.putInt("type",1);
		Bundle bundle3 = new Bundle();
		bundle3.putInt("type",2);
		Bundle bundle4 = new Bundle();
		bundle4.putInt("type",3);
		Bundle bundle5 = new Bundle();
		bundle5.putInt("type",4);
		oneFragment.setArguments(bundle1);
		twoFragment.setArguments(bundle2);
		threeFragment.setArguments(bundle3);
		fourFragment.setArguments(bundle4);
		fiveFragment.setArguments(bundle5);
		fragmentList.add(oneFragment);
		fragmentList.add(twoFragment);
		fragmentList.add(threeFragment);
		fragmentList.add(fourFragment);
		fragmentList.add(fiveFragment);
		mPager.setAdapter(new MyFragmentPagerAdapter(
				getSupportFragmentManager(), fragmentList, tabTitles));
		mPager.setOffscreenPageLimit(4);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()){
			case R.id.title_left_img:
				finish();
				break;
			default:
				break;
		}
	}

}
